home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / game / shoot / ADoom_src_1_2.lha / ADoom_src / d_main.c < prev    next >
C/C++ Source or Header  |  1998-03-08  |  32KB  |  1,227 lines

  1. // Emacs style mode select   -*- C++ -*- 
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION:
  20. //      DOOM main program (D_DoomMain) and game loop (D_DoomLoop),
  21. //      plus functions to determine game mode (shareware, registered),
  22. //      parse command line parameters, configure game parameters (turbo),
  23. //      and call the startup functions.
  24. //
  25. //-----------------------------------------------------------------------------
  26.  
  27.  
  28. static const char rcsid[] = "$Id: d_main.c,v 1.8 1997/02/03 22:45:09 b1 Exp $";
  29.  
  30. #define BGCOLOR         7
  31. #define FGCOLOR         8
  32.  
  33.  
  34. #ifdef NORMALUNIX
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <unistd.h>
  38. #include <sys/types.h>
  39. #include <sys/stat.h>
  40. #include <fcntl.h>
  41. #endif
  42.  
  43.  
  44. #include "doomdef.h"
  45. #include "doomstat.h"
  46.  
  47. #include "dstrings.h"
  48. #include "sounds.h"
  49.  
  50.  
  51. #include "z_zone.h"
  52. #include "w_wad.h"
  53. #include "s_sound.h"
  54. #include "v_video.h"
  55.  
  56. #include "f_finale.h"
  57. #include "f_wipe.h"
  58.  
  59. #include "m_argv.h"
  60. #include "m_misc.h"
  61. #include "m_menu.h"
  62.  
  63. #include "i_system.h"
  64. #include "i_sound.h"
  65. #include "i_video.h"
  66.  
  67. #include "g_game.h"
  68.  
  69. #include "hu_stuff.h"
  70. #include "wi_stuff.h"
  71. #include "st_stuff.h"
  72. #include "am_map.h"
  73.  
  74. #include "p_setup.h"
  75. #include "r_local.h"
  76.  
  77. /* DeHacked Patch !!! */
  78. #include "dehacked.h"
  79.  
  80. #include "d_main.h"
  81.  
  82. //
  83. // D-DoomLoop()
  84. // Not a globally visible function,
  85. //  just included for source reference,
  86. //  called by D_DoomMain, never exits.
  87. // Manages timing and IO,
  88. //  calls all ?_Responder, ?_Ticker, and ?_Drawer,
  89. //  calls I_GetTime, I_StartFrame, and I_StartTic
  90. //
  91. void D_DoomLoop (void);
  92.  
  93.  
  94. char*           wadfiles[MAXWADFILES];
  95.  
  96.  
  97. boolean         devparm;        // started game with -devparm
  98. boolean         nomonsters;     // checkparm of -nomonsters
  99. boolean         respawnparm;    // checkparm of -respawn
  100. boolean         fastparm;       // checkparm of -fast
  101. boolean         rotatemap;      // checkparm of -rotatemap
  102. boolean         maponhu;        // checkparm of -maponhu
  103.  
  104. boolean         drone;
  105.  
  106. boolean         singletics = false; // debug flag to cancel adaptiveness
  107.  
  108.  
  109.  
  110. //extern int soundVolume;
  111. //extern  int   sfxVolume;
  112. //extern  int   musicVolume;
  113.  
  114. extern  boolean inhelpscreens;
  115. extern  boolean maponhu;
  116.  
  117. skill_t         startskill;
  118. int             startepisode;
  119. int             startmap;
  120. boolean         autostart;
  121.  
  122. FILE*           debugfile;
  123.  
  124. boolean         advancedemo;
  125.  
  126.  
  127.  
  128.  
  129. char            wadfile[1024];          // primary wad file
  130. char            mapdir[1024];           // directory of development maps
  131. char            basedefault[1024];      // default file
  132.  
  133.  
  134. void D_CheckNetGame (void);
  135. void D_ProcessEvents (void);
  136. void G_BuildTiccmd (ticcmd_t* cmd);
  137. void D_DoAdvanceDemo (void);
  138.  
  139.  
  140. //
  141. // EVENT HANDLING
  142. //
  143. // Events are asynchronous inputs generally generated by the game user.
  144. // Events can be discarded if no responder claims them
  145. //
  146. event_t         events[MAXEVENTS];
  147. int             eventhead;
  148. int             eventtail;
  149.  
  150.  
  151. //
  152. // D_PostEvent
  153. // Called by the I/O functions when input is detected
  154. //
  155. void D_PostEvent (event_t* ev)
  156. {
  157.     events[eventhead] = *ev;
  158.     eventhead = (++eventhead)&(MAXEVENTS-1);
  159. }
  160.  
  161.  
  162. //
  163. // D_ProcessEvents
  164. // Send all the events of the given timestamp down the responder chain
  165. //
  166. void D_ProcessEvents (void)
  167. {
  168.     event_t*    ev;
  169.         
  170.     // IF STORE DEMO, DO NOT ACCEPT INPUT
  171.     if ( ( gamemode == commercial )
  172.          && (W_CheckNumForName("map01")<0) )
  173.       return;
  174.         
  175.     for ( ; eventtail != eventhead ; eventtail = (++eventtail)&(MAXEVENTS-1) )
  176.     {
  177.         ev = &events[eventtail];
  178.         if (M_Responder (ev))
  179.             continue;               // menu ate the event
  180.         G_Responder (ev);
  181.     }
  182. }
  183.  
  184.  
  185.  
  186.  
  187. //
  188. // D_Display
  189. //  draw current display, possibly wiping it from the previous
  190. //
  191.  
  192. // wipegamestate can be set to -1 to force a wipe on the next draw
  193. gamestate_t     wipegamestate = GS_DEMOSCREEN;
  194. extern  boolean setsizeneeded;
  195. extern  int             showMessages;
  196. void R_ExecuteSetViewSize (void);
  197.  
  198. void D_Display (void)
  199. {
  200.     static  boolean             maponhustate = false;
  201.     static  boolean             viewactivestate = false;
  202.     static  boolean             menuactivestate = false;
  203.     static  boolean             inhelpscreensstate = false;
  204.     static  boolean             fullscreen = false;
  205.     static  gamestate_t         oldgamestate = -1;
  206.     static  int                 borderdrawcount;
  207.     int                         nowtime;
  208.     int                         tics;
  209.     int                         wipestart;
  210.     int                         y;
  211.     boolean                     done;
  212.     boolean                     wipe;
  213.     boolean                     redrawsbar;
  214.  
  215.     if (nodrawers)
  216.         return;                    // for comparative timing / profiling
  217.                 
  218.     redrawsbar = false;
  219.     
  220.     // change the view size if needed
  221.     if (setsizeneeded)
  222.     {
  223.         R_ExecuteSetViewSize ();
  224.         oldgamestate = -1;                      // force background redraw
  225.         borderdrawcount = 3;
  226.     }
  227.  
  228.     // force redraw border if we changed maponhu type
  229.     if (maponhu > 0 && maponhustate == 0)
  230.     {
  231.         oldgamestate = -1;                      // force background redraw
  232.         borderdrawcount = 3;
  233.     }
  234.  
  235.     // save the current screen if about to wipe
  236.     if (gamestate != wipegamestate)
  237.     {
  238.         wipe = true;
  239.         wipe_StartScreen(0, 0, SCREENWIDTH, SCREENHEIGHT);
  240.     }
  241.     else
  242.         wipe = false;
  243.  
  244.     // start updating gfx in screens[0] here
  245.     I_StartUpdate ();
  246.  
  247.     if (gamestate == GS_LEVEL && gametic)
  248.         HU_Erase();
  249.     
  250.     // do buffered drawing
  251.     switch (gamestate)
  252.     {
  253.       case GS_LEVEL:
  254.         if (!gametic)
  255.             break;
  256.         /* Map On Headup Patch - CDE - 97'
  257.         if (automapactive)
  258.             AM_Drawer ();
  259.         */
  260.         if (wipe || (viewheight != SCREENHEIGHT && fullscreen) )
  261.             redrawsbar = true;
  262.         if (inhelpscreensstate && !inhelpscreens)
  263.             redrawsbar = true;              // just put away the help screen
  264.         ST_Drawer (viewheight == SCREENHEIGHT, redrawsbar );
  265.         fullscreen = viewheight == SCREENHEIGHT;
  266.         break;
  267.  
  268.       case GS_INTERMISSION:
  269.         WI_Drawer ();
  270.         break;
  271.  
  272.       case GS_FINALE:
  273.         F_Drawer ();
  274.         break;
  275.  
  276.       case GS_DEMOSCREEN:
  277.         D_PageDrawer ();
  278.         break;
  279.     }
  280.     
  281.     // draw buffered stuff to screen
  282.     I_UpdateNoBlit ();
  283.     
  284.     // draw the view directly
  285.     if (gamestate == GS_LEVEL && (!automapactive || maponhu) && gametic)
  286.         R_RenderPlayerView (&players[displayplayer]);
  287.  
  288.     /* Map On HeadUp Patch - CDE 98' */
  289.     if (gamestate == GS_LEVEL && automapactive)
  290.         AM_Drawer ();
  291.  
  292.     if (gamestate == GS_LEVEL && gametic)
  293.         HU_Drawer ();
  294.     
  295.     // clean up border stuff
  296.     if (gamestate != oldgamestate && gamestate != GS_LEVEL)
  297.         I_SetPalette (W_CacheLumpName ("PLAYPAL",PU_CACHE), 0);
  298.  
  299.     // see if the border needs to be initially drawn
  300.     if (gamestate == GS_LEVEL && oldgamestate != GS_LEVEL)
  301.     {
  302.         viewactivestate = false;        // view was not active
  303.         R_FillBackScreen ();    // draw the pattern into the back screen
  304.     }
  305.  
  306.     // see if the border needs to be updated to the screen
  307.     if (gamestate == GS_LEVEL && (maponhu || !automapactive) /* && scaledviewwidth != 320 */)
  308.     {
  309.         if (menuactive || menuactivestate || !viewactivestate)
  310.             borderdrawcount = 3;
  311.         if (borderdrawcount)
  312.         {
  313.             R_DrawViewBorder ();    // erase old menu stuff
  314.             borderdrawcount--;
  315.         }
  316.     }
  317.  
  318.     maponhustate = maponhu; // CDE'98
  319.     menuactivestate = menuactive;
  320.     viewactivestate = viewactive;
  321.     inhelpscreensstate = inhelpscreens;
  322.     oldgamestate = wipegamestate = gamestate;
  323.     
  324.     // draw pause pic
  325.     if (paused)
  326.     {
  327.         if (automapactive)
  328.             y = 4;
  329.         else
  330.             y = viewwindowy+4;
  331.         V_DrawPatchDirect(viewwindowx+(scaledviewwidth-68)/2,
  332.                           y,0,W_CacheLumpName ("M_PAUSE", PU_CACHE));
  333.     }
  334.  
  335.  
  336.     // menus go directly to the screen
  337.     M_Drawer ();          // menu is drawn even on top of everything
  338.     NetUpdate ();         // send out any new accumulation
  339.  
  340.  
  341.     // normal update
  342.     if (!wipe)
  343.     {
  344.         I_FinishUpdate ();              // page flip or blit buffer
  345.         return;
  346.     }
  347.     
  348.     // wipe update
  349.     wipe_EndScreen(0, 0, SCREENWIDTH, SCREENHEIGHT);
  350.  
  351.     wipestart = I_GetTime () - 1;
  352.  
  353.     do
  354.     {
  355.         do
  356.         {
  357.             nowtime = I_GetTime ();
  358.             tics = nowtime - wipestart;
  359.         } while (!tics);
  360.         wipestart = nowtime;
  361.         done = wipe_ScreenWipe(wipe_Melt
  362.                                , 0, 0, SCREENWIDTH, SCREENHEIGHT, tics);
  363.         I_StartUpdate ();
  364.         I_UpdateNoBlit ();
  365.         M_Drawer ();                   // menu is drawn even on top of wipes
  366.         I_FinishUpdate ();             // page flip or blit buffer
  367.     } while (!done);
  368. }
  369.  
  370.  
  371.  
  372. //
  373. //  D_DoomLoop
  374. //
  375. extern  boolean         demorecording;
  376.  
  377. void D_DoomLoop (void)
  378. {
  379.     if (demorecording)
  380.         G_BeginRecording ();
  381.                 
  382.     if (M_CheckParm ("-debugfile"))
  383.     {
  384.         char    filename[20];
  385.         sprintf (filename,"debug%i.txt",consoleplayer);
  386.         printf ("debug output to: %s\n",filename);
  387.         debugfile = fopen (filename,"w");
  388.     }
  389.         
  390.     I_InitGraphics ();
  391.  
  392.     while (1)
  393.     {
  394.         // frame syncronous IO operations
  395.         I_StartFrame ();                
  396.         
  397.         // process one or more tics
  398.         if (singletics)
  399.         {
  400.             I_StartTic ();
  401.             D_ProcessEvents ();
  402.             G_BuildTiccmd (&netcmds[consoleplayer][maketic%BACKUPTICS]);
  403.             if (advancedemo)
  404.                 D_DoAdvanceDemo ();
  405.             M_Ticker ();
  406.             G_Ticker ();
  407.             gametic++;
  408.             maketic++;
  409.         }
  410.         else
  411.         {
  412.             TryRunTics (); // will run at least one tic
  413.         }
  414.                 
  415.         S_UpdateSounds (players[consoleplayer].mo);// move positional sounds
  416.  
  417.         // Update display, next frame, with current state.
  418.         D_Display ();
  419.  
  420. #if 0
  421. #ifndef SNDSERV
  422.         // Sound mixing for the buffer is snychronous.
  423.         I_UpdateSound();
  424. #endif  
  425.         // Synchronous sound output is explicitly called.
  426. #ifndef SNDINTR
  427.         // Update sound output.
  428.         I_SubmitSound();
  429. #endif
  430. #endif
  431.     }
  432. }
  433.  
  434.  
  435.  
  436. //
  437. //  DEMO LOOP
  438. //
  439. int             demosequence;
  440. int             pagetic;
  441. char                    *pagename;
  442.  
  443.  
  444. //
  445. // D_PageTicker
  446. // Handles timing for warped projection
  447. //
  448. void D_PageTicker (void)
  449. {
  450.     if (--pagetic < 0)
  451.         D_AdvanceDemo ();
  452. }
  453.  
  454.  
  455.  
  456. //
  457. // D_PageDrawer
  458. //
  459. void D_PageDrawer (void)
  460. {
  461.     V_DrawPatchInDirect (0,0, 0, W_CacheLumpName(pagename, PU_CACHE));
  462. }
  463.  
  464.  
  465. //
  466. // D_AdvanceDemo
  467. // Called after each demo or intro demosequence finishes
  468. //
  469. void D_AdvanceDemo (void)
  470. {
  471.     advancedemo = true;
  472. }
  473.  
  474.  
  475. //
  476. // This cycles through the demo sequences.
  477. // FIXME - version dependend demo numbers?
  478. //
  479.  void D_DoAdvanceDemo (void)
  480. {
  481.     players[consoleplayer].playerstate = PST_LIVE;  // not reborn
  482.     advancedemo = false;
  483.     usergame = false;               // no save / end game here
  484.     paused = false;
  485.     gameaction = ga_nothing;
  486.  
  487.     if ( gamemode == retail )
  488.       demosequence = (demosequence+1)%7;
  489.     else
  490.       demosequence = (demosequence+1)%6;
  491.     
  492.     switch (demosequence)
  493.     {
  494.       case 0:
  495.         if ( gamemode == commercial )
  496.             pagetic = 35 * 11;
  497.         else
  498.             pagetic = 170;
  499.         gamestate = GS_DEMOSCREEN;
  500.         pagename = "TITLEPIC";
  501.         if ( gamemode == commercial )
  502.           S_StartMusic(mus_dm2ttl);
  503.         else
  504.           S_StartMusic (mus_intro);
  505.         break;
  506.       case 1:
  507.         G_DeferedPlayDemo ("demo1");
  508.         break;
  509.       case 2:
  510.         pagetic = 200;
  511.         gamestate = GS_DEMOSCREEN;
  512.         pagename = "CREDIT";
  513.         break;
  514.       case 3:
  515.         G_DeferedPlayDemo ("demo2");
  516.         break;
  517.       case 4:
  518.         gamestate = GS_DEMOSCREEN;
  519.         if ( gamemode == commercial)
  520.         {
  521.             pagetic = 35 * 11;
  522.             pagename = "TITLEPIC";
  523.             S_StartMusic(mus_dm2ttl);
  524.         }
  525.         else
  526.         {
  527.             pagetic = 200;
  528.  
  529.             if ( gamemode == retail )
  530.               pagename = "CREDIT";
  531.             else
  532.               pagename = "HELP2";
  533.         }
  534.         break;
  535.       case 5:
  536.         G_DeferedPlayDemo ("demo3");
  537.         break;
  538.         // THE DEFINITIVE DOOM Special Edition demo
  539.       case 6:
  540.         G_DeferedPlayDemo ("demo4");
  541.         break;
  542.     }
  543. }
  544.  
  545.  
  546.  
  547. //
  548. // D_StartTitle
  549. //
  550. void D_StartTitle (void)
  551. {
  552.     gameaction = ga_nothing;
  553.     demosequence = -1;
  554.     D_AdvanceDemo ();
  555. }
  556.  
  557.  
  558.  
  559.  
  560. //      print title for every printed line
  561. char            title[128];
  562.  
  563.  
  564.  
  565. //
  566. // D_AddFile
  567. //
  568. void D_AddFile (char *file)
  569. {
  570.     int     numwadfiles;
  571.     char    *newfile;
  572.         
  573.     for (numwadfiles = 0 ; wadfiles[numwadfiles] ; numwadfiles++)
  574.         ;
  575.  
  576.     newfile = malloc (strlen(file)+1);
  577.     strcpy (newfile, file);
  578.         
  579.     wadfiles[numwadfiles] = newfile;
  580. }
  581.  
  582. //
  583. // IdentifyVersion
  584. // Checks availability of IWAD files by name,
  585. // to determine whether registered/commercial features
  586. // should be executed (notably loading PWAD's).
  587. //
  588. void IdentifyVersion (void)
  589. {
  590.  
  591.     char*       doom1wad;
  592.     char*       doomwad;
  593.     char*       doomuwad;
  594.     char*       doom2wad;
  595.  
  596.     char*       doom2fwad;
  597.     char*       plutoniawad;
  598.     char*       tntwad;
  599.  
  600. #ifdef NORMALUNIX
  601.     static char home[256];
  602.     static char doomwaddir[256];
  603.  
  604.     if (getenv ("DOOMWADDIR") != NULL) {
  605.       strcpy (doomwaddir, getenv("DOOMWADDIR"));
  606.       if (doomwaddir[strlen(doomwaddir)-1] != '/' && doomwaddir[strlen(doomwaddir)-1] != ':')
  607.         strcat (doomwaddir, "/");
  608.     } else
  609.       strcpy (doomwaddir, "PROGDIR:");
  610.  
  611.     // Commercial.
  612.     doom2wad = malloc(strlen(doomwaddir)+1+9+1);
  613.     sprintf(doom2wad, "%sdoom2.wad", doomwaddir);
  614.  
  615.     // Retail.
  616.     doomuwad = malloc(strlen(doomwaddir)+1+8+1);
  617.     sprintf(doomuwad, "%sdoomu.wad", doomwaddir);
  618.     
  619.     // Registered.
  620.     doomwad = malloc(strlen(doomwaddir)+1+8+1);
  621.     sprintf(doomwad, "%sdoom.wad", doomwaddir);
  622.     
  623.     // Shareware.
  624.     doom1wad = malloc(strlen(doomwaddir)+1+9+1);
  625.     sprintf(doom1wad, "%sdoom1.wad", doomwaddir);
  626.  
  627.      // Bug, dear Shawn.
  628.     // Insufficient malloc, caused spurious realloc errors.
  629.     plutoniawad = malloc(strlen(doomwaddir)+1+/*9*/12+1);
  630.     sprintf(plutoniawad, "%splutonia.wad", doomwaddir);
  631.  
  632.     tntwad = malloc(strlen(doomwaddir)+1+9+1);
  633.     sprintf(tntwad, "%stnt.wad", doomwaddir);
  634.  
  635.  
  636.     // French stuff.
  637.     doom2fwad = malloc(strlen(doomwaddir)+1+10+1);
  638.     sprintf(doom2fwad, "%sdoom2f.wad", doomwaddir);
  639.  
  640. #ifdef __SASC
  641.     if (getenv ("HOME") != NULL) {
  642.       strcpy (home, getenv("HOME"));
  643.       if (home[strlen(home)-1] != '/' && home[strlen(home)-1] != ':')
  644.         strcat (home, "/");
  645.     } else
  646.       home[0] = '\0';
  647. #else
  648.     home = getenv ("HOME");
  649.     if (!home)
  650.       I_Error("Please set $HOME to your home directory");
  651. #endif
  652.     sprintf(basedefault, "%s.doomrc", home);
  653. #endif
  654.  
  655.     if (M_CheckParm ("-shdev"))
  656.     {
  657.         gamemode = shareware;
  658.         devparm = true;
  659.         D_AddFile (DEVDATA"doom1.wad");
  660.         D_AddFile (DEVMAPS"data_se/texture1.lmp");
  661.         D_AddFile (DEVMAPS"data_se/pnames.lmp");
  662.         strcpy (basedefault,DEVDATA"default.cfg");
  663.         return;
  664.     }
  665.  
  666.     if (M_CheckParm ("-regdev"))
  667.     {
  668.         gamemode = registered;
  669.         devparm = true;
  670.         D_AddFile (DEVDATA"doom.wad");
  671.         D_AddFile (DEVMAPS"data_se/texture1.lmp");
  672.         D_AddFile (DEVMAPS"data_se/texture2.lmp");
  673.         D_AddFile (DEVMAPS"data_se/pnames.lmp");
  674.         strcpy (basedefault,DEVDATA"default.cfg");
  675.         return;
  676.     }
  677.  
  678.     if (M_CheckParm ("-comdev"))
  679.     {
  680.         gamemode = commercial;
  681.         devparm = true;
  682.         /* I don't bother
  683.         if(plutonia)
  684.             D_AddFile (DEVDATA"plutonia.wad");
  685.         else if(tnt)
  686.             D_AddFile (DEVDATA"tnt.wad");
  687.         else*/
  688.             D_AddFile (DEVDATA"doom2.wad");
  689.             
  690.         D_AddFile (DEVMAPS"cdata/texture1.lmp");
  691.         D_AddFile (DEVMAPS"cdata/pnames.lmp");
  692.         strcpy (basedefault,DEVDATA"default.cfg");
  693.         return;
  694.     }
  695.  
  696.     if ( !access (doom2fwad,R_OK) )
  697.     {
  698.         gamemode = commercial;
  699.         // C'est ridicule!
  700.         // Let's handle languages in config files, okay?
  701.         language = french;
  702.         printf("French version\n");
  703.         D_AddFile (doom2fwad);
  704.         return;
  705.     }
  706.  
  707.     if ( !access (doom2wad,R_OK) )
  708.     {
  709.         gamemode = commercial;
  710.         D_AddFile (doom2wad);
  711.         return;
  712.     }
  713.  
  714.     if ( !access (plutoniawad, R_OK ) )
  715.     {
  716.       gamemode = commercial;
  717.       D_AddFile (plutoniawad);
  718.       return;
  719.     }
  720.  
  721.     if ( !access ( tntwad, R_OK ) )
  722.     {
  723.       gamemode = commercial;
  724.       D_AddFile (tntwad);
  725.       return;
  726.     }
  727.  
  728.     if ( !access (doomuwad,R_OK) )
  729.     {
  730.       gamemode = retail;
  731.       D_AddFile (doomuwad);
  732.       return;
  733.     }
  734.  
  735.     if ( !access (doomwad,R_OK) )
  736.     {
  737.       gamemode = registered;
  738.       D_AddFile (doomwad);
  739.       return;
  740.     }
  741.  
  742.     if ( !access (doom1wad,R_OK) )
  743.     {
  744.       gamemode = shareware;
  745.       D_AddFile (doom1wad);
  746.       return;
  747.     }
  748.  
  749.     printf("Game mode indeterminate.\n");
  750.     gamemode = indetermined;
  751.  
  752.     // We don't abort. Let's see what the PWAD contains.
  753.     //exit(1);
  754.     //I_Error ("Game mode indeterminate\n");
  755. }
  756.  
  757. //
  758. // Find a Response File
  759. //
  760. void FindResponseFile (void)
  761. {
  762.     int             i;
  763.         
  764.     for (i = 1;i < myargc;i++)
  765.         if (myargv[i][0] == '@')
  766.         {
  767.             FILE *          handle;
  768.             int             size;
  769.             int             k;
  770.             int             index;
  771.             int             indexinfile;
  772.             char    *infile;
  773.             char    *file;
  774.             char    *moreargs[20];
  775.             char    *firstargv;
  776.                         
  777.             // READ THE RESPONSE FILE INTO MEMORY
  778.             handle = fopen (&myargv[i][1],"rb");
  779.             if (!handle)
  780.             {
  781.                 printf ("\nNo such response file!");
  782.                 exit(1);
  783.             }
  784.             printf("Found response file %s!\n",&myargv[i][1]);
  785.             fseek (handle,0,SEEK_END);
  786.             size = ftell(handle);
  787.             fseek (handle,0,SEEK_SET);
  788.             file = malloc (size);
  789.             fread (file,size,1,handle);
  790.             fclose (handle);
  791.                         
  792.             // KEEP ALL CMDLINE ARGS FOLLOWING @RESPONSEFILE ARG
  793.             for (index = 0,k = i+1; k < myargc; k++)
  794.                 moreargs[index++] = myargv[k];
  795.                         
  796.             firstargv = myargv[0];
  797.             myargv = malloc(sizeof(char *)*MAXARGVS);
  798.             memset(myargv,0,sizeof(char *)*MAXARGVS);
  799.             myargv[0] = firstargv;
  800.                         
  801.             infile = file;
  802.             indexinfile = k = 0;
  803.             indexinfile++;  // SKIP PAST ARGV[0] (KEEP IT)
  804.             do
  805.             {
  806.                 myargv[indexinfile++] = infile+k;
  807.                 while(k < size &&
  808.                       ((*(infile+k)>= ' '+1) && (*(infile+k)<='z')))
  809.                     k++;
  810.                 *(infile+k) = 0;
  811.                 while(k < size &&
  812.                       ((*(infile+k)<= ' ') || (*(infile+k)>'z')))
  813.                     k++;
  814.             } while(k < size);
  815.                         
  816.             for (k = 0;k < index;k++)
  817.                 myargv[indexinfile++] = moreargs[k];
  818.             myargc = indexinfile;
  819.         
  820.             // DISPLAY ARGS
  821.             printf("%d command-line args:\n",myargc);
  822.             for (k=1;k<myargc;k++)
  823.                 printf("%s\n",myargv[k]);
  824.  
  825.             break;
  826.         }
  827. }
  828.  
  829.  
  830. //
  831. // D_DoomMain
  832. //
  833. void D_DoomMain (void)
  834. {
  835.     int             p;
  836.     char                    file[256];
  837.  
  838.     FindResponseFile ();
  839.         
  840.     IdentifyVersion ();
  841.         
  842.     setbuf (stdout, NULL);
  843.     modifiedgame = false;
  844.         
  845.     nomonsters = M_CheckParm ("-nomonsters");
  846.     respawnparm = M_CheckParm ("-respawn");
  847.     fastparm = M_CheckParm ("-fast");
  848.     rotatemap = M_CheckParm ("-rotatemap");
  849.     devparm = M_CheckParm ("-devparm");
  850.     maponhu = (M_CheckParm ("-maponhu") != 0);
  851.  
  852.     if (M_CheckParm ("-altdeath"))
  853.         deathmatch = 2;
  854.     else if (M_CheckParm ("-deathmatch"))
  855.         deathmatch = 1;
  856.  
  857.     switch ( gamemode )
  858.     {
  859.       case retail:
  860.         sprintf (title,
  861.                  "                         "
  862.                  "The Ultimate DOOM Startup v%i.%i"
  863.                  "                           ",
  864.                  VERSION/100,VERSION%100);
  865.         break;
  866.       case shareware:
  867.         sprintf (title,
  868.                  "                            "
  869.                  "DOOM Shareware Startup v%i.%i"
  870.                  "                           ",
  871.                  VERSION/100,VERSION%100);
  872.         break;
  873.       case registered:
  874.         sprintf (title,
  875.                  "                            "
  876.                  "DOOM Registered Startup v%i.%i"
  877.                  "                           ",
  878.                  VERSION/100,VERSION%100);
  879.         break;
  880.       case commercial:
  881.         sprintf (title,
  882.                  "                         "
  883.                  "DOOM 2: Hell on Earth v%i.%i"
  884.                  "                           ",
  885.                  VERSION/100,VERSION%100);
  886.         break;
  887. /*FIXME
  888.        case pack_plut:
  889.         sprintf (title,
  890.                  "                   "
  891.                  "DOOM 2: Plutonia Experiment v%i.%i"
  892.                  "                           ",
  893.                  VERSION/100,VERSION%100);
  894.         break;
  895.       case pack_tnt:
  896.         sprintf (title,
  897.                  "                     "
  898.                  "DOOM 2: TNT - Evilution v%i.%i"
  899.                  "                           ",
  900.                  VERSION/100,VERSION%100);
  901.         break;
  902. */
  903.       default:
  904.         sprintf (title,
  905.                  "                     "
  906.                  "Public DOOM - v%i.%i"
  907.                  "                           ",
  908.                  VERSION/100,VERSION%100);
  909.         break;
  910.     }
  911.     
  912.     printf ("%s\n",title);
  913.  
  914.     if (devparm)
  915.         printf(D_DEVSTR);
  916.     
  917.     if (M_CheckParm("-cdrom"))
  918.     {
  919.         printf(D_CDROM);
  920. #ifdef __SASC
  921.         mkdir("c:\\doomdata");
  922. #else
  923.         mkdir("c:\\doomdata",0);
  924. #endif
  925.         strcpy (basedefault,"c:/doomdata/default.cfg");
  926.     }   
  927.     
  928.     // turbo option
  929.     if ( (p=M_CheckParm ("-turbo")) )
  930.     {
  931.         int     scale = 200;
  932.         extern int forwardmove[2];
  933.         extern int sidemove[2];
  934.         
  935.         if (p<myargc-1)
  936.             scale = atoi (myargv[p+1]);
  937.         if (scale < 10)
  938.             scale = 10;
  939.         if (scale > 400)
  940.             scale = 400;
  941.         printf ("turbo scale: %i%%\n",scale);
  942.         forwardmove[0] = forwardmove[0]*scale/100;
  943.         forwardmove[1] = forwardmove[1]*scale/100;
  944.         sidemove[0] = sidemove[0]*scale/100;
  945.         sidemove[1] = sidemove[1]*scale/100;
  946.     }
  947.     
  948.     // add any files specified on the command line with -file wadfile
  949.     // to the wad list
  950.     //
  951.     // convenience hack to allow -wart e m to add a wad file
  952.     // prepend a tilde to the filename so wadfile will be reloadable
  953.     p = M_CheckParm ("-wart");
  954.     if (p)
  955.     {
  956.         myargv[p][4] = 'p';     // big hack, change to -warp
  957.  
  958.         // Map name handling.
  959.         switch (gamemode )
  960.         {
  961.           case shareware:
  962.           case retail:
  963.           case registered:
  964.             sprintf (file,"~"DEVMAPS"E%cM%c.wad",
  965.                      myargv[p+1][0], myargv[p+2][0]);
  966.             printf("Warping to Episode %s, Map %s.\n",
  967.                    myargv[p+1],myargv[p+2]);
  968.             break;
  969.             
  970.           case commercial:
  971.           default:
  972.             p = atoi (myargv[p+1]);
  973.             if (p<10)
  974.               sprintf (file,"~"DEVMAPS"cdata/map0%i.wad", p);
  975.             else
  976.               sprintf (file,"~"DEVMAPS"cdata/map%i.wad", p);
  977.             break;
  978.         }
  979.         D_AddFile (file);
  980.     }
  981.         
  982.     p = M_CheckParm ("-file");
  983.     if (p)
  984.     {
  985.         // the parms after p are wadfile/lump names,
  986.         // until end of parms or another - preceded parm
  987.         modifiedgame = true;            // homebrew levels
  988.         while (++p != myargc && myargv[p][0] != '-')
  989.             D_AddFile (myargv[p]);
  990.     }
  991.  
  992.     /* DeHacked Patch !! */
  993.     p = M_CheckParm ("-deh");
  994.     if (p)
  995.     {
  996.         // the parms after p are wadfile/lump names,
  997.         // until end of parms or another - preceded parm
  998.         //modifiedgame = true;            // homebrew levels
  999.         while (++p != myargc && myargv[p][0] != '-')
  1000.             DE_AddDeh(myargv[p]);
  1001.     }
  1002.  
  1003.     p = M_CheckParm ("-playdemo");
  1004.  
  1005.     if (!p)
  1006.         p = M_CheckParm ("-timedemo");
  1007.  
  1008.     if (p && p < myargc-1)
  1009.     {
  1010.         sprintf (file,"%s.lmp", myargv[p+1]);
  1011.         D_AddFile (file);
  1012.         printf("Playing demo %s.lmp.\n",myargv[p+1]);
  1013.     }
  1014.     
  1015.     // get skill / episode / map from parms
  1016.     startskill = sk_medium;
  1017.     startepisode = 1;
  1018.     startmap = 1;
  1019.     autostart = false;
  1020.  
  1021.                 
  1022.     p = M_CheckParm ("-skill");
  1023.     if (p && p < myargc-1)
  1024.     {
  1025.         startskill = myargv[p+1][0]-'1';
  1026.         autostart = true;
  1027.     }
  1028.  
  1029.     p = M_CheckParm ("-episode");
  1030.     if (p && p < myargc-1)
  1031.     {
  1032.         startepisode = myargv[p+1][0]-'0';
  1033.         startmap = 1;
  1034.         autostart = true;
  1035.     }
  1036.         
  1037.     p = M_CheckParm ("-timer");
  1038.     if (p && p < myargc-1 && deathmatch)
  1039.     {
  1040.         int     time;
  1041.         time = atoi(myargv[p+1]);
  1042.         printf("Levels will end after %d minute",time);
  1043.         if (time>1)
  1044.             printf("s");
  1045.         printf(".\n");
  1046.     }
  1047.  
  1048.     p = M_CheckParm ("-avg");
  1049.     if (p && p < myargc-1 && deathmatch)
  1050.         printf("Austin Virtual Gaming: Levels will end after 20 minutes\n");
  1051.  
  1052.     p = M_CheckParm ("-warp");
  1053.     if (p && p < myargc-1)
  1054.     {
  1055.         if (gamemode == commercial)
  1056.             startmap = atoi (myargv[p+1]);
  1057.         else
  1058.         {
  1059.             startepisode = myargv[p+1][0]-'0';
  1060.             startmap = myargv[p+2][0]-'0';
  1061.         }
  1062.         autostart = true;
  1063.     }
  1064.     
  1065.     // init subsystems
  1066.     printf ("V_Init: allocate screens.\n");
  1067.     V_Init ();
  1068.  
  1069.     printf ("M_LoadDefaults: Load system defaults.\n");
  1070.     M_LoadDefaults ();              // load before initing other systems
  1071.  
  1072.     printf ("Z_Init: Init zone memory allocation daemon. \n");
  1073.     Z_Init ();
  1074.  
  1075.     printf ("W_Init: Init WADfiles.\n");
  1076.     W_InitMultipleFiles (wadfiles);
  1077.     
  1078.  
  1079.     // Check for -file in shareware
  1080.     if (modifiedgame)
  1081.     {
  1082.         // These are the lumps that will be checked in IWAD,
  1083.         // if any one is not present, execution will be aborted.
  1084.         char name[23][8]=
  1085.         {
  1086.             "e2m1","e2m2","e2m3","e2m4","e2m5","e2m6","e2m7","e2m8","e2m9",
  1087.             "e3m1","e3m3","e3m3","e3m4","e3m5","e3m6","e3m7","e3m8","e3m9",
  1088.             "dphoof","bfgga0","heada1","cybra1","spida1d1"
  1089.         };
  1090.         int i;
  1091.         
  1092.         if ( gamemode == shareware)
  1093.             I_Error("\nYou cannot -file with the shareware "
  1094.                     "version. Register!");
  1095.  
  1096.         // Check for fake IWAD with right name,
  1097.         // but w/o all the lumps of the registered version. 
  1098.         if (gamemode == registered)
  1099.             for (i = 0;i < 23; i++)
  1100.                 if (W_CheckNumForName(name[i])<0)
  1101.                     I_Error("\nThis is not the registered version.");
  1102.     }
  1103.     
  1104.     // Iff additonal PWAD files are used, print modified banner
  1105.     if (modifiedgame)
  1106.     {
  1107.         /*m*/printf (
  1108.             "===========================================================================\n"
  1109.             "ATTENTION:  This version of DOOM has been modified.  If you would like to\n"
  1110.             "get a copy of the original game, call 1-800-IDGAMES or see the readme file.\n"
  1111.             "        You will not receive technical support for modified games.\n"
  1112.             "                      press enter to continue\n"
  1113.             "===========================================================================\n"
  1114.             );
  1115.         getchar ();
  1116.     }
  1117.         
  1118.  
  1119.     // Check and print which version is executed.
  1120.     switch ( gamemode )
  1121.     {
  1122.       case shareware:
  1123.       case indetermined:
  1124.         printf (
  1125.             "===========================================================================\n"
  1126.             "                                Shareware!\n"
  1127.             "===========================================================================\n"
  1128.         );
  1129.         break;
  1130.       case registered:
  1131.       case retail:
  1132.       case commercial:
  1133.         printf (
  1134.             "===========================================================================\n"
  1135.             "                 Commercial product - do not distribute!\n"
  1136.             "         Please report software piracy to the SPA: 1-800-388-PIR8\n"
  1137.             "===========================================================================\n"
  1138.         );
  1139.         break;
  1140.         
  1141.       default:
  1142.         // Ouch.
  1143.         break;
  1144.     }
  1145.  
  1146.     printf ("M_Init: Init miscellaneous info.\n");
  1147.     M_Init ();
  1148.  
  1149.     printf ("R_Init: Init DOOM refresh daemon - ");
  1150.     R_Init ();
  1151.  
  1152.     printf ("\nP_Init: Init Playloop state.\n");
  1153.     P_Init ();
  1154.  
  1155.     printf ("I_Init: Setting up machine state.\n");
  1156.     I_Init ();
  1157.  
  1158.     printf ("D_CheckNetGame: Checking network game status.\n");
  1159.     D_CheckNetGame ();
  1160.  
  1161.     printf ("S_Init: Setting up sound.\n");
  1162.     S_Init (snd_SfxVolume /* *8 */, snd_MusicVolume /* *8*/ );
  1163.  
  1164.     printf ("HU_Init: Setting up heads up display.\n");
  1165.     HU_Init ();
  1166.  
  1167.     printf ("ST_Init: Init status bar.\n");
  1168.     ST_Init ();
  1169.  
  1170.     // check for a driver that wants intermission stats
  1171.     p = M_CheckParm ("-statcopy");
  1172.     if (p && p<myargc-1)
  1173.     {
  1174.         // for statistics driver
  1175.         extern  void*   statcopy;                            
  1176.  
  1177.         statcopy = (void*)atoi(myargv[p+1]);
  1178.         printf ("External statistics registered.\n");
  1179.     }
  1180.     
  1181.     // start the apropriate game based on parms
  1182.     p = M_CheckParm ("-record");
  1183.  
  1184.     if (p && p < myargc-1)
  1185.     {
  1186.         G_RecordDemo (myargv[p+1]);
  1187.         autostart = true;
  1188.     }
  1189.         
  1190.     p = M_CheckParm ("-playdemo");
  1191.     if (p && p < myargc-1)
  1192.     {
  1193.         singledemo = true;              // quit after one demo
  1194.         G_DeferedPlayDemo (myargv[p+1]);
  1195.         D_DoomLoop ();  // never returns
  1196.     }
  1197.         
  1198.     p = M_CheckParm ("-timedemo");
  1199.     if (p && p < myargc-1)
  1200.     {
  1201.         G_TimeDemo (myargv[p+1]);
  1202.         D_DoomLoop ();  // never returns
  1203.     }
  1204.         
  1205.     p = M_CheckParm ("-loadgame");
  1206.     if (p && p < myargc-1)
  1207.     {
  1208.         if (M_CheckParm("-cdrom"))
  1209.             sprintf(file, "c:\\doomdata\\"SAVEGAMENAME"%c.dsg",myargv[p+1][0]);
  1210.         else
  1211.             sprintf(file, SAVEGAMENAME"%c.dsg",myargv[p+1][0]);
  1212.         G_LoadGame (file);
  1213.     }
  1214.         
  1215.  
  1216.     if ( gameaction != ga_loadgame )
  1217.     {
  1218.         if (autostart || netgame)
  1219.             G_InitNew (startskill, startepisode, startmap);
  1220.         else
  1221.             D_StartTitle ();                // start up intro loop
  1222.  
  1223.     }
  1224.  
  1225.     D_DoomLoop ();  // never returns
  1226. }
  1227.